package com.maple.test;

import com.maple.util.LanUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

/**
 * <p></p>
 *
 * @author maple
 */
@RestController
@RequestMapping("/test/language")
public class LanguageTestController {

    @GetMapping("/lan")
    public String changeLanguage(@RequestParam String lang, HttpServletRequest request) {
        // 设置新的Locale
        Locale newLocale = new Locale(lang);
        request.getSession().setAttribute("sessionLocaleResolver.LOCALE", newLocale);
        return "ok";
    }


    @GetMapping("/greeting")
    public String greeting() {
        // return LanUtil.getMsg("greeting");
        return LanUtil.getMsg("greeting", null);
    }

}
